﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlAgilityPack;
using Newtonsoft.Json.Linq;

namespace TaobaoLibrary
{
    public class Review
    {
        public Review(JToken jtoken, Product product)
        {
            Product = product;
            Content = jtoken["content"].ToString();
            if (jtoken["append"] != null)
            {
                AppendContent = jtoken["append"].ToString();
            }
            if (jtoken["reply"] != null)
            {
                ReplyContent = jtoken["reply"].ToString();
            }
            Rate = int.Parse(jtoken["rate"].ToString());
            if (!(bool)jtoken["user"]["anony"])
            {
                User = new User(jtoken["user"]["userId"].ToString(), jtoken["user"]["nick"].ToString());
            }
            Date = DateTime.Parse(jtoken["date"].ToString());
        }

        /// <summary>
        /// 评论正文
        /// </summary>
        public string Content
        {
            get;
            protected set;
        }

        /// <summary>
        /// 追加评论正文
        /// </summary>
        public string AppendContent
        {
            get;
            protected set;
        }

        /// <summary>
        /// 掌柜回复正文
        /// </summary>
        public string ReplyContent
        {
            get;
            protected set;
        }

        /// <summary>
        /// 评分 1:好评 0:中评 -1:差评
        /// </summary>
        public int Rate
        {
            get;
            protected set;
        }

        /// <summary>
        /// 评论时间
        /// </summary>
        public DateTime Date
        {
            get;
            protected set;
        }

        public Product Product
        {
            get;
            protected set;
        }

        public User User
        {
            get;
            protected set;
        }
    }
}
